package com.tianliangedu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.tianliangedu.manager.db.WeiBoDBManager;

/**
 * 注解声明，该类为Controller类 并自动加载所需要的其它类
 */
@Controller
public class WordCloudController {
	@Autowired
	private WeiBoDBManager weiBoDBManager;

	@RequestMapping("/wordcloud_original")
	String getHotWordsOriginal(ModelMap modelMap) {
		return "bak_wordcloud";
	}

	@RequestMapping("/wordcloud")
	String getHotWords(ModelMap modelMap) {
		JSONArray jsonArray = weiBoDBManager.getHotWordsJsonArray(null);
		modelMap.put("result", jsonArray.toJSONString());
		return "wordcloud";
	}

	@RequestMapping("/wordcloud_release")
	String getHotWords4Release(String day_seq, ModelMap modelMap) {
		if (day_seq == null) {
			day_seq = "20120102";
		}
		JSONArray jsonArray = weiBoDBManager.getHotWordsJsonArray(day_seq);
		modelMap.put("result", jsonArray.toJSONString());
		return "wordcloud_release";
	}

	@RequestMapping("/wordcloud_json")
	@ResponseBody
	String getJsonHotWords(String day_seq) {
		JSONArray jsonArray = weiBoDBManager.getHotWordsJsonArray(day_seq);
		return jsonArray.toJSONString();
	}

	// 主方法，像一般的Java类一般去右击run as application时候，执行该方法
	public static void main(String[] args) throws Exception {
		SpringApplication.run(WordCloudController.class, args);
	}
}
